package com.paul.girl.exception;

import com.paul.girl.domain.Result;
import com.paul.girl.utils.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionHandle {

    private final  static Logger logger= LoggerFactory.getLogger(ExceptionHandle.class);

    @ExceptionHandler(Exception.class)
    public Result handle(Exception e) {
        if (e instanceof GirlException) {
            return ResultUtil.failed(e.getMessage(), ((GirlException) e).getCode());
        }else {
            logger.error("系统错误={}",e);
            return  ResultUtil.failed("未知错误...",-1);
        }
    }
}
